<template>
    <view>
        <view class="tab-item">
            <uni-segmented-control :current="current" :values="items" :style-type="styleType" :active-color="activeColor" @clickItem="onClickItem" />
            <block></block>
        </view>
        <view class="tab-content2">
            <view v-show="current === 0">
                <block v-if="lists[current].list.length > 0">
                    <view class="nova-list">
                        <ay-job v-for="(item, index) in lists[current].list" :key="index" page="yz-share" :item="item" :itemIndex="index"></ay-job>
                        <block></block>
                    </view>
                    <view style="height: 20rpx;"></view>
                </block>
                <block v-else>
                    <view class="nothing">
                        <image src="/static/img/nothing.png" />
                        <view style="text-align:center">暂无相关数据</view>
                    </view>
                </block>
            </view>
            <view v-show="current === 1">
                <block v-if="lists[current].list.length > 0">
                    <view class="nova-list">
                        <ay-job v-for="(item, index) in lists[current].list" :key="index" page="yz-share" :item="item"></ay-job>
                        <block></block>
                    </view>
                    <view style="height: 20rpx;"></view>
                </block>
                <block v-else>
                    <view class="nothing">
                        <image src="/static/img/nothing.png" />
                        <view style="text-align:center">暂无相关数据</view>
                    </view>
                </block>
            </view>
        </view>
        <image class="yz-share-add" src="../../static/yz/yz-share-add.png" @click="goShare"></image>
    </view>
</template>

<script>
import conf from '../../common/conf.js';
import uniSegmentedControl from '../../components/uni-segmented-control/uni-segmented-control.vue';
import ayJob from '../c/li-aunty.vue';
export default {
    name: 'yz-share',
    components: {
        uniSegmentedControl,
        ayJob
    },
    data() {
        return {
            items: ['业主分享', '我的分享'],
            current: 0,
            colorIndex: 0,
            activeColor: '#ff6702',
            styleType: 'text',
            lists: [
                {
                    params: {
                        page: 0,
                        row: 10
                    },
                    reload: false,
                    list: []
                },
                {
                    params: {
                        page: 0,
                        row: 10
                    },
                    reload: false,
                    list: []
                }
            ]
        };
    },
    created() {
        uni.$on('yzShareAy', this.yzShareAy)
    },
    destroyed() {
        uni.$off('yzShareAy')
    },
    methods: {
        yzShareAy() {
            
        },
        onClickItem(i) {
            if (!this.$checkIdentification()) {
                return;
            }
            this.current = i;
            let seg = this.lists[this.current];
            if (seg.list.length === 0) {
                this.loadData();
            }
        },
        async loadData() {
            let seg = this.lists[this.current];
            let data = { ...seg.params };
            //data.workNumber = this.$global.workNumber;
            if (seg.reload) {
                data.page = 1;
            } else {
                data.page = data.page + 1;
            }
            console.log(data);
            let res = await this.$request.post({
                url: this.current === 0 ? '/publish/publishUserShare' : '/publish/publishShareUser',
                data: data,
                loadingTip: '加载中...'
            });
            let res2 = [];
            if (res) {
                res.forEach(item => {
                    // let target = {
                    //     birthday: item.birthday,
                    //     tip: [conf.ayTypes[item.type]],
                    //     price: item.price,
                    //     job: item
                    // };
                    // target.job.publish_id = item.publish_share_id;
                    // target.job.name = item.userName;
                    item.birthday = item.job.birthday
                    item.job.name = item.job.userName
                    item.job.telephone = item.job.userPhone
                    if (typeof(item.tip) == 'string') {
                        item.tip = [item.tip]
                    }
                    res2.push(item);
                });
            }
            console.log(res2);
            if (seg.reload) {
                seg.list = res2 || [];
            } else {
                seg.list = seg.list.concat(res2);
            }
            seg.params.page++;
            seg.reload = false;
            uni.stopPullDownRefresh();
        },
        refresh() {
            let seg = this.lists[this.current];
            seg.reload = true;
            this.loadData()
        },
        loadMore() {
            this.loadData();
        },
        show() {
            if (this.zwlist === undefined || this.zwlist.length == 0) {
                this.refresh();
            }
        },
        goShare() {
            if (!this.$checkIdentification()) {
                return;
            }
            uni.navigateTo({
                url: '../c/p-publish-category?delegate=1'
            });
        }
    },
    onLoad() {
        this.loadData();
    },
    onPullDownRefresh() {
        let seg = this.lists[this.current];
        seg.reload = true;
        this.loadData();
    },
    onReachBottom() {
        this.loadData();
    }
};
</script>

<style lang="scss">
.tab-item {
    padding: 10rpx 0;
    left: 0;
    top: 80rpx;
    /* #ifndef H5 */
    top: 0;
    /* #endif */
    position: fixed;
    width: 100%;
    z-index: 10;
    background-color: white;
}
.tab-content2 {
    width: 100%;
    position: fixed;
    left: 0;
    margin-top: 72rpx;
    top: 0;
}
.yz-share-add {
    width: 100rpx;
    height: 100rpx;
    position: fixed;
    right: 30rpx;
    bottom: 120rpx;
}
</style>
